package com.cheung.leetcode.str;

public class LC415 {

    public static String addStrings(String num1, String num2) {

        StringBuilder sb = new StringBuilder();
        int add = 0;
        int i = num1.length() - 1;
        int j = num2.length() - 1;
        while (i >= 0 || j >= 0 || add != 0) {
            int i1 = i >= 0 ? num1.charAt(i) - '0' : 0;
            int i2 = j >= 0 ? num2.charAt(j) - '0' : 0;
            sb.append((i1 + i2 + add) % 10);
            add = (i1 + i2 + add) / 10;
            i--;
            j--;
        }

        return sb.reverse().toString();
    }

    public static void main(String[] args) {
        System.out.println(addStrings("999", "99"));
    }
}
